import { IPSSysDBColumn } from './ipssys-dbcolumn';
import { IPSSysDBScheme } from './ipssys-dbscheme';
import { IPSSysDBTable } from './ipssys-dbtable';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSSysDBColumnImpl extends PSModelObjectImpl implements IPSSysDBColumn {
  get codeName(): string {
    return this.M.codeName;
  }

  get codeName2(): string {
    return this.M.codeName2;
  }

  get createSql(): string {
    return this.M.createSql;
  }

  get dataType(): string {
    return this.M.dataType;
  }

  get defaultValue(): string {
    return this.M.defaultValue;
  }

  get dropSql(): string {
    return this.M.dropSql;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get length(): number {
    return this.M.length != null ? this.M.length : -1;
  }

  get logicName(): string {
    return this.M.logicName;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get precision(): number {
    return this.M.precision != null ? this.M.precision : 0;
  }

  protected refpssysdbcolumn: IPSSysDBColumn | null = null;

  getRefPSSysDBColumn(): IPSSysDBColumn | null {
    if (this.refpssysdbcolumn != null) return this.refpssysdbcolumn;
    const value = this.M.getRefPSSysDBColumn;
    if (value == null) {
      return null;
    }
    this.refpssysdbcolumn = this.getPSModel4('database.IPSSysDBColumn', value, 'getRefPSSysDBColumn') as IPSSysDBColumn;
    return this.refpssysdbcolumn;
  }

  get refPSSysDBColumn(): IPSSysDBColumn | null {
    return this.getRefPSSysDBColumn();
  }

  getRefPSSysDBColumnMust(): IPSSysDBColumn {
    const value = this.getRefPSSysDBColumn();
    if (value == null) {
      throw new Error('未指定引用数据列');
    }
    return value;
  }

  protected refpssysdbtable: IPSSysDBTable | null = null;

  getRefPSSysDBTable(): IPSSysDBTable | null {
    if (this.refpssysdbtable != null) return this.refpssysdbtable;
    const value = this.M.getRefPSSysDBTable;
    if (value == null) {
      return null;
    }
    const ipssysdbscheme = this.getParentPSModelObject('database.IPSSysDBScheme') as IPSSysDBScheme;
    if (ipssysdbscheme != null) {
      this.refpssysdbtable = ipssysdbscheme.findPSSysDBTable(value);
    }
    return this.refpssysdbtable;
  }

  get refPSSysDBTable(): IPSSysDBTable | null {
    return this.getRefPSSysDBTable();
  }

  getRefPSSysDBTableMust(): IPSSysDBTable {
    const value = this.getRefPSSysDBTable();
    if (value == null) {
      throw new Error('未指定引用数据表');
    }
    return value;
  }

  get stdDataType(): 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 {
    return this.M.stdDataType;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get autoIncrement(): boolean {
    return this.M.autoIncrement != null ? this.M.autoIncrement : false;
  }

  get fKey(): boolean {
    return this.M.fKey != null ? this.M.fKey : false;
  }

  get nullable(): boolean {
    return this.M.nullable != null ? this.M.nullable : false;
  }

  get pKey(): boolean {
    return this.M.pKey != null ? this.M.pKey : false;
  }

  get unsigned(): boolean {
    return this.M.unsigned != null ? this.M.unsigned : false;
  }

  get cls(): string {
    return 'PSSysDBColumnImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'database.IPSSysDBColumn') return true;
    return super.instanceof(cls);
  }
}
